﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using SafoverWpfFw;
using Safover.LidarCollector.Core;
using Safover.LidarCollector.Managers;

namespace Safover.LidarCollector.ViewModel
{
    public class HardwareIndicatorViewModel : BaseViewModel
    {
        public DeviceCondition RotaryTableCondition { get; private set; }
        public string RotaryTableConditionDescription { get; private set; }
        public bool IsRotaryTableVirtual { get; private set; }


        public DeviceCondition AcquisitionCardCondition { get; private set; }
        public string AcquisitionCardConditionDescription { get; private set; }
        public bool IsAcquisitionCardVirtual { get; private set; }


        public DeviceCondition OpticalMaserCondition { get; private set; }
        public string OpticalMaserConditionDescription { get; private set; }
        public bool IsOpticalMaserVirtual { get; private set; }



        public DeviceCondition GpsLocatorCondition { get; private set; }
        public string GpsLocatorConditionDescription { get; private set; }
        public bool IsGpsLocatorVirtual { get; private set; }



        public DeviceCondition CameraCondition { get; private set; }
        public string CameraConditionDescription { get; private set; }
        public bool IsCameraVirtual { get; private set; }


        public DeviceCondition ElectronicCompassCondition { get; private set; }
        public string ElectronicCompassConditionDescription { get; private set; }
        public bool IsElectronicCompassVirtual { get; private set; }


        public HardwareIndicatorViewModel()
        {
            DeviceManager.DeviceFactoryInstance.DeviceConditionChangedEvent += OnDeviceConditionChanged;

            SyncStatus();
        }

        private void SyncStatus()
        {
            RotaryTableCondition = DeviceManager.DeviceFactoryInstance.RotaryTableCondition;
            IsRotaryTableVirtual = DeviceManager.DeviceFactoryInstance.IsRotaryTableVirtual;
            RotaryTableConditionDescription = DeviceManager.DeviceFactoryInstance.RotaryTableConditionDescription;


            AcquisitionCardCondition = DeviceManager.DeviceFactoryInstance.AcquisitionCardCondition;
            IsAcquisitionCardVirtual = DeviceManager.DeviceFactoryInstance.IsAcquisitionCardVirtual;
            AcquisitionCardConditionDescription = DeviceManager.DeviceFactoryInstance.AcquisitionCardConditionDescription;

            OpticalMaserCondition = DeviceManager.DeviceFactoryInstance.OpticalMaserCondition;
            IsOpticalMaserVirtual = DeviceManager.DeviceFactoryInstance.IsOpticalMaserVirtual;
            OpticalMaserConditionDescription = DeviceManager.DeviceFactoryInstance.OpticalMaserConditionDescription;

            GpsLocatorCondition = DeviceManager.DeviceFactoryInstance.GpsLocatorCondition;
            IsGpsLocatorVirtual = DeviceManager.DeviceFactoryInstance.IsGpsLocatorVirtual;
            GpsLocatorConditionDescription = DeviceManager.DeviceFactoryInstance.GpsLocatorConditionDescription;

            CameraCondition = DeviceManager.DeviceFactoryInstance.CameraCondition;
            IsCameraVirtual = DeviceManager.DeviceFactoryInstance.IsCameraVirtual;
            CameraConditionDescription = DeviceManager.DeviceFactoryInstance.CameraConditionDescription;

            ElectronicCompassCondition = DeviceManager.DeviceFactoryInstance.ElectronicCompassCondition;
            IsElectronicCompassVirtual = DeviceManager.DeviceFactoryInstance.IsElectronicCompassVirtual;
            ElectronicCompassConditionDescription = DeviceManager.DeviceFactoryInstance.ElectronicCompassConditionDescription;

        }

        private void OnDeviceConditionChanged(DeviceConditionChangedEventArgs e)
        {
            switch (e.DeviceType)
            {
                case DeviceType.RotaryTable:
                    {
                        RotaryTableCondition = e.DeviceCondition;
                        RotaryTableConditionDescription = e.Description;
                    }
                    break;
                case DeviceType.OpticalMaser:
                    {
                        OpticalMaserCondition = e.DeviceCondition;
                        OpticalMaserConditionDescription = e.Description;
                    }
                    break;
                case DeviceType.AcquisitionCard:
                    {
                        AcquisitionCardCondition = e.DeviceCondition;
                        AcquisitionCardConditionDescription = e.Description;
                    }
                    break;
                case DeviceType.Camera:
                    {
                        CameraCondition = e.DeviceCondition;
                        CameraConditionDescription = e.Description;
                    }
                    break;
                case DeviceType.GpsLocator:
                    {
                        GpsLocatorCondition = e.DeviceCondition;
                        GpsLocatorConditionDescription = e.Description;
                    }
                    break;
                case DeviceType.ElectronicCompass:
                    {
                        ElectronicCompassCondition = e.DeviceCondition;
                        ElectronicCompassConditionDescription = e.Description;
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
